package bliffoscope.engine;


import java.util.ArrayList;
import java.util.BitSet;
import java.util.LinkedList;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author ddatta
 */
public class Subject {
    private ArrayList<BitSet> bitSet = null;
    private int totalBitCount = 0;
    private ArrayList<Integer> orderedBitCountList = null;
    private int height=0, width=0;
    private String type ;

    
    Subject(){
        this.bitSet = new ArrayList<BitSet>();
        this.orderedBitCountList = new ArrayList<Integer>();
    }

    public ArrayList<BitSet> getBitSet() {
        
        return bitSet;
    }
    
    public void add(BitSet b){
        if(b.isEmpty())
            return;
        
        this.bitSet.add(b);
        this.totalBitCount+=b.cardinality();
        height++;
        if(b.length()>width)
            width = b.length();
        
    }

    public void setBitSet(ArrayList<BitSet> bitSet) {
        this.bitSet = bitSet;
    }

    public int getTotalBitCount() {
        return totalBitCount;
    }

    public void setTotalBitCount(int totalBitCount) {
        this.totalBitCount = totalBitCount;
    }
    
    @Override
    public String toString(){
        String retVal = "";
        for(BitSet b : this.bitSet)
            retVal= retVal+ b.toString()+"\r";
        return retVal;
    }
    
    public void trimColumns(){
        //trimming 
        boolean leftColumnEmpty = true;
        while(leftColumnEmpty){
            for(BitSet b : this.bitSet){
                if(b.nextSetBit(0)==0)
                    leftColumnEmpty = false;
            }

            if(leftColumnEmpty){
                ArrayList<BitSet> newBitSet = new ArrayList<BitSet>(height);
                for(BitSet b : this.bitSet){
                    newBitSet.add(b.get(1, b.length()));
                }
                this.bitSet = newBitSet;
            }
        }
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }
    
    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
    
}
